﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：周传雄 
    //
    // 文件名：DistributePlanList.cs
    // 文件功能描述：退货管理
    // 创建标识：周传雄2009-05-12
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;
using System.Collections.Generic;
using HZ.DrugTrade.Web;
using HZ.Common;

namespace HZ.DrugTrade.Web.Enterprise.ReturnManage
{
    public partial class ReturnRefuse : BasePage
    {
        public ReturnRefuse()
        {
            this.ModuleNo = Module.退货单管理.ToString();
        }
        public string str_ReturnSerialID = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            //上一页传值判断
            if (!string.IsNullOrEmpty(Request.QueryString["RSID"]))
            {
                str_ReturnSerialID = Request.QueryString["RSID"].ToString();
            }
            //标签间 传值判断
            else if (!string.IsNullOrEmpty(Request["strID"]))
            {
                str_ReturnSerialID = Request["strID"].ToString();
            }
            else { return; }
            if (!IsPostBack)
            {
                QueryResult();
            }

        }
        private void QueryResult()
        {

            IList<Model.View.ReturnMerchandiseDetail> LisReturnMerchandiseDetail = new List<Model.View.ReturnMerchandiseDetail>();
            Model.Query.ReturnMerchandiseDetail qryCondition = new Model.Query.ReturnMerchandiseDetail();
            User user = CurrentAccount.GetUser();
            qryCondition.CompanyID = user.Org.OrgID;
            qryCondition.ReturnOrderStatus = 2;//退货单状态：0(空单) 1 (未提交) 2(已提交)
            qryCondition.GoodsName = txtProdcutname.Text.ToString().Trim();

            qryCondition.Outlookc = txtOutLookc.Text.ToString().Trim();
            qryCondition.ReturnTimeFrom = new HZ.Common.ConvertHelper(txt01.Text.ToString().Trim()).ToDateTime;
            qryCondition.ReturnTimeTo = new HZ.Common.ConvertHelper(txt02.Text.ToString().Trim()).ToDateTime;
            qryCondition.HospitalName = txtHospitalName.Text.ToString().Trim();
            qryCondition.CompanyName_SC = txtCompanyName.Text.ToString().Trim();
            //qryCondition.Pack = txtPack.Text.ToString().Trim();
            qryCondition.ReturnName = txtProdcutname.Text.ToString().Trim();
            qryCondition.PinyinCode = this.txtpinyincode.Text.Trim();
            if (str_ReturnSerialID != null && str_ReturnSerialID != "")
            {
                qryCondition.ReturnSerialID = str_ReturnSerialID;
            }
            qryCondition.ProjectID = this.ddlProjectid.SelectedValue;
            //else { confirm.Enabled = false; refuse.Enabled = false; }
            qryCondition.ReturnState = 2;//未确认
            qryCondition.SortFields = " ReturnTime desc ";
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            int totalCount = 0;
            IBLL_Purchase iPurchase = Factory.BLL_Purchase();
            LisReturnMerchandiseDetail = iPurchase.GetReturnReturnMerchandiseDetail(qryCondition, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwreturn.DataSource = LisReturnMerchandiseDetail;
            gvwreturn.DataBind();

        }
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            QueryResult();
        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            QueryResult();
        }
        /// <summary>
        /// 确认退货
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Confirm_Click(object sender, EventArgs e)
        {
            IList<ReturnMerchandiseDetail> ReturnDetaillsit = new List<ReturnMerchandiseDetail>();
            IBLL_Purchase iPurchase = Factory.BLL_Purchase();
            for (int i = 0; i < this.gvwreturn.Rows.Count; i++)
            {
                System.Web.UI.HtmlControls.HtmlInputCheckBox chk = (System.Web.UI.HtmlControls.HtmlInputCheckBox)gvwreturn.Rows[i].FindControl("bSelect");
                if (chk.Checked == true)
                {
                    ReturnMerchandiseDetail aa = new ReturnMerchandiseDetail();
                    aa.ReturnSerialDetailID = chk.Value;
                    ReturnDetaillsit.Add(aa);
                }

            }

            int nSuccess = iPurchase.ConfirmReturnMerchandise_Batch(ReturnDetaillsit);
            if (nSuccess == 1)
            {
                //PageError("已经确认成功！", Request.RawUrl);
                HZ.Web.WebUtil.Alert("已经确认成功!", this);
                QueryResult();
            }
            else
            {
                //PageError("确认失败！", Request.RawUrl);
                HZ.Web.WebUtil.Alert("确认失败!", this);
            }

        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Write("<script language=javascript> history.go(-2);</script>");
        }
    }
}
